package com.ruoyi.project.para.paeaParaAuditAmt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.oms.paeaAuType.service.IPaeaAuTypeService;
import com.ruoyi.project.para.paeaParaAuditAmt.domain.PaeaParaAuditAmt;
import com.ruoyi.project.para.paeaParaAuditAmt.service.IPaeaParaAuditAmtService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 重点监控限额Controller
 *
 * @author ruoyi
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/para/paeaParaAuditAmt")
public class PaeaParaAuditAmtController extends BaseController
{
    private String prefix = "para/paeaParaAuditAmt";

    @Autowired
    private IPaeaParaAuditAmtService paeaParaAuditAmtService;

    @Autowired
    private IPaeaAuTypeService paeaAuTypeService;

    @RequiresPermissions("para:paeaParaAuditAmt:view")
    @GetMapping()
    public String paeaParaAuditAmt()
    {
        return prefix + "/paeaParaAuditAmt";
    }

    /**
     * 查询重点监控限额列表
     */
    @RequiresPermissions("para:paeaParaAuditAmt:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaParaAuditAmt paeaParaAuditAmt)
    {
        startPage();
        List<PaeaParaAuditAmt> list = paeaParaAuditAmtService.list(new QueryWrapper<>(paeaParaAuditAmt));
        return getDataTable(list);
    }

    /**
     * 导出重点监控限额列表
     */
    @RequiresPermissions("para:paeaParaAuditAmt:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaParaAuditAmt paeaParaAuditAmt)
    {
        List<PaeaParaAuditAmt> list = paeaParaAuditAmtService.list(new QueryWrapper<>(paeaParaAuditAmt));
        ExcelUtil<PaeaParaAuditAmt> util = new ExcelUtil<PaeaParaAuditAmt>(PaeaParaAuditAmt.class);
        return util.exportExcel(list, "paeaParaAuditAmt");
    }

    /**
     * 新增重点监控限额
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("paeaAuTypes", paeaAuTypeService.selectPaeaAuTypeAll());
        return prefix + "/add";
    }

    /**
     * 新增保存重点监控限额
     */
    @RequiresPermissions("para:paeaParaAuditAmt:add")
    @Log(title = "重点监控限额", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaParaAuditAmt paeaParaAuditAmt)
    {
        return toAjax(paeaParaAuditAmtService.saveOrUpdate(paeaParaAuditAmt));
    }

    /**
     * 修改重点监控限额
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaParaAuditAmt paeaParaAuditAmt = paeaParaAuditAmtService.getById(id);
        mmap.put("paeaParaAuditAmt", paeaParaAuditAmt);
        return prefix + "/edit";
    }

    /**
     * 修改保存重点监控限额
     */
    @RequiresPermissions("para:paeaParaAuditAmt:edit")
    @Log(title = "重点监控限额", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaParaAuditAmt paeaParaAuditAmt)
    {
        return toAjax(paeaParaAuditAmtService.saveOrUpdate(paeaParaAuditAmt));
    }

    /**
     * 删除重点监控限额
     */
    @RequiresPermissions("para:paeaParaAuditAmt:remove")
    @Log(title = "重点监控限额", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaParaAuditAmtService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
